package com.fqgame.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fqgame.user.entity.PointsRecord;
import com.fqgame.user.mapper.PointsRecordMapper;
import com.fqgame.user.service.PointsRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 积分记录服务实现类
 */
@Slf4j
@Service
public class PointsRecordServiceImpl extends ServiceImpl<PointsRecordMapper, PointsRecord> implements PointsRecordService {

    /**
     * 添加积分记录
     */
    @Override
    public boolean addPointsRecord(Long userId, Integer points, Integer type, String reason, String businessId) {
        log.info("添加积分记录，用户ID：{}，积分：{}，类型：{}，原因：{}", userId, points, type, reason);
        
        PointsRecord record = new PointsRecord();
        record.setUserId(userId);
        record.setPoints(points);
        record.setType(type);
        record.setReason(reason);
        record.setBusinessId(businessId);
        record.setCreateTime(LocalDateTime.now());
        
        boolean success = this.save(record);
        if (success) {
            log.info("积分记录添加成功，记录ID：{}", record.getId());
        } else {
            log.error("积分记录添加失败");
        }
        
        return success;
    }
}